package com.hnucm.cooklife.ui.fragment;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.hnucm.cooklife.R;
import com.hnucm.cooklife.adapter.CollectAdapter;
import com.hnucm.cooklife.adapter.RecomAdapter;
import com.hnucm.cooklife.base.BaseFragment;
import com.hnucm.cooklife.base.utils.LoginUtils;

import com.hnucm.cooklife.bean.me.DishColl;
import com.hnucm.cooklife.contract.meDishColl.Contract;
import com.hnucm.cooklife.presenter.me.MeDishCollPresenter;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MeDishCollFragment extends BaseFragment<Contract.IMeDishCollView, MeDishCollPresenter> implements Contract.IMeDishCollView ,
        com.scwang.smartrefresh.layout.listener.OnLoadMoreListener,
        com.scwang.smartrefresh.layout.listener.OnRefreshListener{

    private Context mContext;
    private CollectAdapter mRecomAdapter;
    private List<DishColl> mDishCollList = new ArrayList<>();

    @BindView(R.id.recom_recycler)
    RecyclerView mRecyclerView;

    @BindView(R.id.refresh_layout)
    SmartRefreshLayout mSmartRefreshLayout;

    @BindView(R.id.layout_error)
    ViewGroup mLayoutError;

    @Override
    protected int getContentViewId() {
        return R.layout.me_dish_fragment;
    }

    @Override
    protected void init() {
        mContext = getContext().getApplicationContext();
        initAdapter();
        mPresenter.loadMeDishColl(LoginUtils.getLoginId());
    }
    private void initAdapter() {
        GridLayoutManager manager = new GridLayoutManager(getContext(), 2);
        mRecyclerView.setLayoutManager(manager);
        mRecomAdapter = new CollectAdapter(mContext,mDishCollList);
        mRecyclerView.setAdapter(mRecomAdapter);
//        mRecomAdapter.setOnItemClickListener(new RecomAdapter.onItemClickListener() {
//            @Override
//            public void onSeleClickListener(View view, int position) {
//                Intent intent = new Intent(getActivity(), DishCollDetailActivity.class);
//                intent.putExtra("DishCollId",mDishCollList.get(position).DishCollId);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent);
//            }
//        });
    }


    @Override
    protected MeDishCollPresenter createPresenter() {
        return new MeDishCollPresenter();
    }

    @Override
    public void onLoading() {

    }

    @Override
    public void onLoadingFailed() {

    }

    @Override
    public void onLoadSuccess() {

    }

    @Override
    public void onLoadMeDishColl(List<DishColl> DishCollList) {
        mDishCollList.clear();
        mDishCollList.addAll(DishCollList);
        mRecomAdapter.setDishList(mDishCollList);
    }

    @Override
    public void onRefreshMeDishColl(List<DishColl> DishCollList) {
        mDishCollList.addAll(DishCollList);
        mRecomAdapter.setDishList(mDishCollList);
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {

    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {

    }
}
